// 项目信息
function findReports($scope, CertusFormAjax, CertusJsonAjax) {

    var deptIds = "";
    var compIds = "";
    this.getDepts = function () {
        var company = $("#company").val();
        if (company != "") {
            findCompDepts(company, deptIds);
        } else {
            findCompDepts(compIds, deptIds);
        }
    }

    this.findCompDepts = function (company, depts) {
        CertusFormAjax.ajax("findCompDepts", {
            "compCodes": company,
            "deptIds": depts,
            "isBm":"BM"
        }, function (response) {
            var data = response.data;
            $scope.dept = data;
        });
    }
    this.findAllDepts = function (dept) {
        CertusFormAjax.ajax("findQDepts", {
            "deptIds": dept
        }, function (response) {
            var data = response.data;
            $scope.dept = data;
        });
    }
    CertusFormAjax.ajax("isCrcd", {
        "code": "BMOKR"
    }, function (response) {
        var data = JSON.parse(response.data);
        deptIds = data.deptCode;
        compIds = data.comanyCode;
        if (data.comanyCode != "") {
            CertusFormAjax.ajax("companyListByCode", {
                "code": data.comanyCode
            }, function (response) {
                $scope.comp = JSON.parse(response.data);
            });
            findCompDepts(data.comanyCode, deptIds);
        } else {
            $("#company").attr("disabled", "disabled");
            findAllDepts(data.deptCode);
        }
        if (data.isTrue == true) {
            searchs(deptIds, compIds, getBeforeDate(-2), getBeforeDate(2));
        } else {
            CertusFormAjax.ajax("getDeptCode", {}, function (response) {
                var data1 = response.data;
                $scope.deptCode = data1;
                $("#deptCode").attr("disabled", "disabled");
                //默认查询
                searchs(data1, compIds, getBeforeDate(-2), getBeforeDate(2));
            });
        }
    });

    this.searchs = function (deptCode, compCode, startTime, endTime) {
        //项目进展
        var msgColumns1 = [{
            id: 'pro_name',
            title: '项目名称',
            type: 'string',
            width: 150,
            columnClass: 'text-center',
        }, {
            id: 'krs_desc',
            title: '关键成果',
            type: 'string',
            width: 200,
            columnClass: 'text-left',
        }, {
            id: 'rw_desc',
            title: '进展和困难',
            type: 'string',
            width: 200,
            columnClass: 'text-left',
        }, {
            id: 'next_plan',
            title: '下一步计划',
            type: 'string',
            columnClass: 'text-left'
        }, {
            id: 'user_name',
            title: '负责人',
            type: 'string',
            width: 75,
            columnClass: 'text-center'
        }, {
            id: 'finish_cycle',
            title: '进展周期',
            type: 'string',
            width: 130,
            columnClass: 'text-center'
        }, {
            id: 'update_time',
            title: '更新时间',
            type: 'date',
            width: 100,
            format: 'yyyy-MM-dd',
            otype: 'time_stamp_ms',
            columnClass: 'text-center',
        }, {
            id: 'operation',
            title: '操作',
            width: 60,
            type: 'string',
            columnClass: 'text-center',
            resolution: function (value, record, column, grid, dataNo, columnNo) {
                var content = '';
                content += '<button class="btn btn-xs btn-success" onclick="todp(' + record.id + ');"><i class="fa fa-edit"></i>  点评</button>';
                return content;
            }
        }];
        $("#msgContainer11").empty();
        $("#msgToolBarContainer11").empty();
        CertusJsonAjax.dataInit("findOkrs", {
            "deptCode": deptCode,
            "compCode": compCode,
            "startTime": startTime,
            "endTime": endTime
        }, msgColumns1, 'msgContainer11', 'msgToolBarContainer11');

        //未填写进展的项目列表
        var msgColumns4 = [{
            id: 'user_name',
            title: '子任务负责人',
            type: 'string',
            width: 100,
            columnClass: 'text-center',
        }, {
            id: 'department_name',
            title: '归属部门',
            type: 'string',
            width: 200,
            columnClass: 'text-center',
        }, {
            id: 'pro_name',
            title: '项目名称',
            type: 'string',
            width: 200,
            columnClass: 'text-center',
        }, {
            id: 'krs_desc',
            title: '关键成果',
            type: 'string',
            columnClass: 'text-left',
        }];
        $("#msgContainer4").empty();
        $("#msgToolBarContainer4").empty();
        CertusJsonAjax.dataInit("findManNoOkrs", {
            "deptCode": deptCode,
            "compCode": compCode,
            "startTime": startTime,
            "endTime": endTime
        }, msgColumns4, 'msgContainer4', 'msgToolBarContainer4');
    }
    $(".searchs").on('click', function () {
        var startTime = $("#datetime-10").val();
        var endTime = $("#datetime-20").val();
        var deptCode = $("#deptCode").val();
        var company = $("#company").val();
        if (company == "") {
            company = compIds;
        }
        if (deptCode == "") {
            deptCode = deptIds;
        }
        searchs(deptCode, company, startTime, endTime);
    });
}
$("#datetime-10").val(getBeforeDate(-2));
$("#datetime-20").val(getBeforeDate(2));
//n为你要传入的参数，当前为0，前一天为-1，后一天为1
function getBeforeDate(n) {
    var date = new Date();
    var year, month, day;
    date.setDate(date.getDate() + n);
    year = date.getFullYear();
    month = date.getMonth() + 1;
    day = date.getDate();
    s = year + '-' + (month < 10 ? ('0' + month) : month) + '-' + (day < 10 ? ('0' + day) : day);
    return s;
}

function todp(pid) {
    location.href = "#/toOkrJzdp/" + pid;
}